home *** CD-ROM | disk | FTP | other *** search
/ CD PowerPlay 10 / CD Powerplay Issue 10 (February 1996).iso / hints / onefall / omfed / omfedt2.c next >
Encoding:
C/C++ Source or Header  |  1994-11-03  |  8.1 KB  |  279 lines

  1. //===========================================================================
  2. // Project  : OMFEDIT
  3. // Module   : omfedit.c
  4. // Purpose  : edit the pilot files of Epic Megagames' One Must Fall (TM)
  5. // Notice   : use however you like, but hold me blameless
  6. // Author   : David Bollinger, CIS# 72510,3623
  7. // Created  : 10/16/94
  8. // Revised  : Paul and Jim Kenney, CIS# 72604, 3253
  9. // Notes    : compiled with Borland C++ 3.1, small model
  10. //---------------------------------------------------------------------------
  11. //
  12. // IMPORTANT:  REGISTER YOUR COPY OF "ONE MUST FALL" TODAY !
  13. //
  14. //             BACKUP YOUR PILOT FILE BEFORE EDITING !
  15. //
  16. //             EAT YOUR VEGETABLES AND FLOSS BETWEEN MEALS !
  17. //
  18. //---------------------------------------------------------------------------
  19. //
  20. // WHAT THIS PROGRAM DOES (CURRENTLY):  Simply gives your pilot more money,
  21. //    you can then do with it as you like.  If you really need to cheat you
  22. //    can run it multiple times on the same pilot file, or change the amount
  23. //    of illicit money in the function call and recompile.  Below is a
  24. //    rough list of some other data values - experiment at your own risk.
  25. //    If you come up with something, though, it would be cool to share it!
  26. //
  27. // Description of Pilot Files (*.CHR):
  28. //
  29. // Encoding method: Cyclical key XOR (initial key value 0xAC)
  30. //
  31. // PILOT DATA INTERPRETATION: (very tentative)
  32. // (obviously, it would be nice to wrap this into a structure)
  33. //
  34. // Decimal                                                         Interpret
  35. // Offset     Type    Meaning                                      Confidence
  36. // -------    ----    -----------------------------------------    ----------
  37. // 000-003            always zero?
  38. // 004-019    byte    name                                         high+
  39. // 022-023    int     wins                                         high+
  40. // 024-025    int     losses                                       high+
  41. // 026        byte    rank                                         high
  42. // 028      -+        arm power/leg power                          low
  43. // 029       |bit     leg power/arm speed                          low
  44. // 030       |pack    leg speed/armor                              low
  45. // 031      -+        stun resitance                               low
  46. // 040-043    long    money (in K$)                                high+
  47. // 044        byte    second body color                            high
  48. // 045        byte    third body color                             high
  49. // 046        byte    main body color                              high
  50. // 047-059    byte    tournament filename                          high
  51. // 060-090    byte    tournament description                       med
  52. // 091-103    byte    tournament picture filename                  high
  53. // 260-262            changes when arm/leg speed/power changes?    low-
  54. //
  55. // 263-1399           god only knows (encoded)
  56. // 1400-1559          elam only knows (not encoded)
  57. //
  58. // 1560(?)-EOF        pilot picture bitmap, format unknown         low-
  59. //---------------------------------------------------------------------------
  60. //
  61. // Limitations:
  62. // The count of 1400 encoded bytes is PROBABLY right, but...
  63. // Fortunately, due to XOR encoding, we can decode/encode a few too many/
  64. //    too few bytes and everything else still works.
  65. //
  66. // The bitmap does not APPEAR to be encoded, just a wacky format.
  67. //
  68. // Hint (for what it's worth):  the bitmap format MAY be a series of 3
  69. //    ints (maybe offsets and counts) followed by the actual pixel data
  70. //    for each line, variable width lines.  If you want to make your own
  71. //    bitmaps you'll need to figure this out.
  72. //
  73. // This is left as an exercise for the reader, there will be a test at
  74. //    the end of the semester  :) 
  75. //---------------------------------------------------------------------------
  76.  
  77. //===========
  78. // directives
  79. //-----------
  80.  
  81. //=========
  82. // includes
  83. //---------
  84. #include <stdio.h>
  85. #include <stdlib.h>
  86. #include <string.h>
  87. #include <io.h>
  88. #include <fcntl.h>
  89. #include <sys\types.h>
  90. #include <ctype.h>
  91. #include <sys\stat.h>
  92.  
  93.  
  94. //========
  95. // defines
  96. //--------
  97.  
  98. #define CODED_SIZE             1400          // # of coded bytes, roughly
  99.  
  100. //===================
  101. // typedefs & structs
  102. //-------------------
  103. typedef unsigned char uchar;
  104. typedef unsigned int uint;
  105. typedef struct omf {
  106.    long zero;
  107.    char name[15];
  108.    char none1[2];
  109.    int wins;
  110.    int losses;
  111.    int rank:8;
  112.    char none2;
  113.    char arm_power;
  114.    char leg_power;
  115.    char leg_speed;
  116.    int stun_resistance:8;
  117.    char none3[6];
  118.    long money;
  119.    int  body_color2:8;
  120.    int  body_color3:8;
  121.    int  body_main:8;
  122.    char tourn_file[12];
  123.    char tourn_desc[30];
  124.    char tourn_pic[12];
  125.    char none4[157];
  126.    int  arm_leg;
  127.    char filler[1136];
  128.    char filler2[159];
  129.    } omfr;
  130.  
  131.  
  132. //===========
  133. // prototypes
  134. //-----------
  135. void EnDeCode(omfr *);
  136. long strtolong(char *);
  137.  
  138. //========
  139. // globals
  140. //--------
  141. char  pilotfile[13];
  142.  
  143. //============================================================================
  144. main(int argc, char *argv[])
  145.    {
  146.  
  147.    char input[40];
  148.    char sel[2];
  149.    int in;
  150.    int filesize;
  151.    char *ptr;
  152.    omfr *omfrec;
  153.    struct stat statbuf;
  154.  
  155.    if (argc < 2)
  156.       {
  157.       printf("\nInput Pilotfile Name. ");
  158.       gets(pilotfile);
  159.       }
  160.    else
  161.       strncpy(pilotfile, argv[1], 12);
  162.  
  163.    in = open(pilotfile,O_RDWR | S_IREAD | S_IWRITE | O_BINARY);
  164.    if (in == -1)
  165.       {
  166.       printf("\nFile not found");
  167.       return 0;
  168.       }
  169.  
  170.    stat(pilotfile,&statbuf);
  171.    filesize = statbuf.st_size;
  172.    omfrec = malloc((int) filesize);
  173.  
  174.    read(in,omfrec,filesize);
  175.  
  176.    EnDeCode(omfrec);
  177.    do
  178.    {
  179.    printf("\n                Name is : %s",omfrec->name);
  180.    printf("\n");
  181.    printf("\n1 Change wins           Currently : %i",omfrec->wins);
  182.    printf("\n2 Change losses         Currently : %i",omfrec->losses);
  183.    printf("\n3 Change rank           Currently : %d",omfrec->rank);
  184.    printf("\n*4 Change arm-leg power Currently : %d",omfrec->arm_power);
  185.    printf("\n*5 Change arm-leg speed Currently : %d",omfrec->leg_power);
  186.    printf("\n*6 Change stun res.     Currently : %d",omfrec->stun_resistance);
  187.    printf("\n7 Change money          Currently : %ld",omfrec->money);
  188.    printf("\nQ Quit + save");
  189.    printf("\nX Quit");
  190.    printf("\n\nAn * means USE AT YOUR OWN RISK. UNKNOWN EFFECT.");
  191.    printf("\nEnter selection please. ");
  192.  
  193.    gets(sel);
  194.    strupr(sel);
  195.  
  196.    switch (sel[0])
  197.    {
  198.    case '1':
  199.    printf("\nEnter the new number for wins. ");
  200.    gets (input);
  201.    omfrec->wins = strtolong(input);
  202.    break;
  203.  
  204.    case '2':
  205.    printf("\nEnter the new number for losses. ");
  206.    gets (input);
  207.    omfrec->losses = strtolong(input);
  208.    break;
  209.  
  210.    case '3':
  211.    printf("\nEnter the new number for rank. ");
  212.    gets(input);
  213.    omfrec->rank = strtolong(input);
  214.    break;
  215.  
  216.    case '4':
  217.    printf("\nEnter new arm-leg power. ");
  218.    gets(input);
  219.    omfrec->arm_power = strtolong(input);
  220.    break;
  221.  
  222.    case '5':
  223.    printf("\nEnter new arm-leg speed. ");
  224.    gets(input);
  225.    omfrec->leg_power = strtolong(input);
  226.    break;
  227.  
  228.  
  229.    case '6':
  230.    printf("\nEnter new stun res. ");
  231.    gets(input);
  232.    omfrec->stun_resistance = strtolong(input);
  233.    break;
  234.  
  235.    case '7':
  236.    printf("\nEnter new amount of money. ");
  237.    gets(input);
  238.    omfrec->money = strtolong(input);
  239.    break;
  240.  
  241.    case 'Q':
  242.    EnDeCode(omfrec);
  243.    lseek(in,0L,SEEK_SET);
  244.    write(in,omfrec,filesize);
  245.    break;
  246.  
  247.    case 'X':
  248.    break;
  249.    }
  250.  
  251.    } while (sel[0] != 'X' && sel[0] != 'Q');
  252.  
  253.  
  254.    close(in);
  255.  
  256.    free(omfrec);
  257.    return 0;
  258.    }
  259.  
  260. long strtolong(char *input)
  261. {
  262. long work;
  263. sscanf(input,"%ld",&work);
  264. return(work);
  265. }
  266.  
  267. //============================================================================
  268. // XOR coding is reflexive, can use same routine for encode/decode
  269. //----------------------------------------------------------------------------
  270. void EnDeCode(omfr *omfrec)
  271.    {
  272.    register int i;
  273.    uchar *pptr=(char *) omfrec;
  274.    uchar key=0xac;
  275.  
  276.    for (i=CODED_SIZE; i>=0; i--)
  277.       *pptr++ ^= key++;
  278.    }
  279.